﻿//<TunynetCopyright>
//--------------------------------------------------------------
//<copyright>青岛拓宇网络科技有限公司 2005-2008</copyright>
//<version>V0.5</verion>
//<createdate>2008-3-29</createdate>
//<author>mazq</author>
//<email>mazq@tunynet.com</email>
//<log date="2008-3-29">创建</log>
//--------------------------------------------------------------
//</TunynetCopyright>

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ChinaCustoms.Framework.DeluxeWorks.Library.OGUPermission;
using ChinaCustoms.Qingdao.Workflow.Permissions;
using System.Collections.Generic;
using ChinaCustoms.Qingdao.Workflow.Supports;

namespace ChinaCustoms.Qingdao.Workflow.Web
{
    /// <summary>
    /// Summary description for ManageBasePage
    /// </summary>
    public class ManageBasePage : Page
    {
        public ManageBasePage()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            bool hasPermission = false;

            if (Request.IsAuthenticated)
            {
                IUser currentUser = ChinaCustomsPermissionWrapper.GetUser(PermissionUtils.StripIrrespectiveCharsForLogOnName(Context.User.Identity.Name));
                if (currentUser != null)
                {
                    //检查当前用户是不是总管理员
                    RoleCollection userRoles = currentUser.Roles["APP_ADMIN"];
                    if (userRoles != null && userRoles.Count > 0)
                    {
                        foreach (IRole role in userRoles)
                        {
                            if (role.CodeName.Equals("ADMINISTRATOR_ROLE", StringComparison.CurrentCultureIgnoreCase))
                            {
                                this.isAdministrator = true;
                                hasPermission = true;
                                break;
                            }
                        }
                    }

                    if (!this.IsAdministrator)
                    {
                        this.applicationCodeNamesForManager = WorkflowManagerRoles.GetApplicationCodeNames(currentUser);
                        if (this.applicationCodeNamesForManager != null && this.applicationCodeNamesForManager.Count > 0)
                        {
                            hasPermission = true;
                        }
                    }
                }
            }

            if (!hasPermission)
            {
                Response.Redirect("~/ErrorMessage.aspx", true);
            }

        }



        private bool isAdministrator = false;
        /// <summary>
        /// 当前用户是不是管理员
        /// </summary>
        public bool IsAdministrator
        {
            get { return isAdministrator; }
            //set { isAdministrator = value; }
        }

        private List<string> applicationCodeNamesForManager = null;
        /// <summary>
        /// 当前用户可以管理的ApplicationCodeName
        /// </summary>
        public List<string> ApplicationCodeNamesForManager
        {
            get { return applicationCodeNamesForManager; }
            //set { applicationCodeNamesForManager = value; }
        }





    }
}